package nccloud.impl.pu.praybillquery;

import java.util.List;

import nc.bs.framework.common.NCLocator;
import nc.impl.pubapp.pattern.data.bill.BillQuery;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.ui.pub.print.IDataSource;
import nc.vo.pu.m20.entity.PraybillItemVO;
import nc.vo.pu.praybillquery.PraybillqueryHVO;
import nc.vo.pub.BusinessException;
import nccloud.commons.lang.ArrayUtils;
import nccloud.pubitf.platform.print.AbstractPrintService;
import nccloud.pubitf.platform.print.IPrintInfo;
import nccloud.pubitf.platform.print.vo.PrintInfo;
import nccloud.pubitf.scmpub.pub.print.BaseMetaPrintTimesService;
import nccloud.web.hr.print.HRNccMetaDataDataSource;

public class PraybillPrintOperator extends AbstractPrintService {
	 

	@Override
	public IDataSource[] getDataSources(IPrintInfo info) {
		PrintInfo printInfo = (PrintInfo) info;
		IUAPQueryBS bssv = NCLocator.getInstance().lookup(IUAPQueryBS.class);
		String[] pks = printInfo.getIds();
		if (ArrayUtils.isEmpty(pks)) {
			return new IDataSource[] { new  HRNccMetaDataDataSource(new Object[0]) };

		} else {
			List<PraybillqueryHVO> vos=null;
			try {
				vos = (List<PraybillqueryHVO>) bssv.executeQuery("select * from  po_praybill_b body "
						+ " where pk_praybill_b in('"+String.join("','", pks)+ "') "
								+ "   ORDER by (CASE WHEN length(vbdef20)>=10 then substr (vbdef20, 0, 10 ) ELSE '' END ) || (SELECT b.vbillcode FROM po_praybill_b "
								+ " a INNER JOIN po_praybill b ON a.pk_praybill=b.pk_praybill WHERE a.pk_praybill_b =po_praybill_b.pk_praybill_b ) desc  ", new BeanListProcessor(PraybillqueryHVO.class));
			} catch (BusinessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace(); 
			}
		 
			IDataSource dateSource = new HRNccMetaDataDataSource(vos.toArray(new PraybillqueryHVO[0]));
			return new IDataSource[] { dateSource };
		}
	}
 

	 
}